package arraylistdemo;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author 12629
 * @Date 2022/3/12 7:47
 * @Description：
 */
public class TestDemo {


    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>();
        List<Integer> list = new ArrayList<>();
        list.add(1);
        ret.add(list);//第一行已经存在了
        for (int i = 1; i < numRows; i++) {
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);
            //j < i
            for (int j = 1; j < i; j++) {
                //获取上一行
                List<Integer> preRow = ret.get(i-1);
                int val = preRow.get(j)+preRow.get(j-1);
                curRow.add(val);
            }
            curRow.add(1);
            ret.add(curRow);
        }
        return  ret;
    }


    public static void main(String[] args) {

    }


    public static void main2(String[] args) {
        MyArrayList myArrayList = new MyArrayList();
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.add(4);
        myArrayList.add(5);
        myArrayList.add(6);
        myArrayList.myToString();

        System.out.println(myArrayList.size());

        myArrayList.remove(3);
        myArrayList.myToString();


//        System.out.println(myArrayList.contains(16));//true
//        System.out.println(myArrayList.indexOf(61));//5
//        try {
//            System.out.println(myArrayList.get(10));
//        }catch (RuntimeException e) {
//            e.printStackTrace();
//        }
//        System.out.println("hello");
    }
    public static void main1(String[] args) {
        // 此时底层的数组 大小 默认是0  ，
        ArrayList<Integer> list = new ArrayList<>();
        ArrayList<Integer> list2 = new ArrayList<>(20);

        //当你第一次进行add的时候，此时大小才被分为了10

        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);

        System.out.println(list);
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println("=============");
        for (Integer x : list) {
            System.out.print(x+" ");
        }
    }
}
